package dialog;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.BackgroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import net.ck.hzq.R;

import Utils.ScreenUtil;

public class YinsiDialog extends BaseDialog {

    private OnConfirmListener3 mOnConfirmListener;

    public static YinsiDialog newInstance(String partnerName) {
        YinsiDialog dialog = new YinsiDialog();
        Bundle arguments = new Bundle();
        arguments.putString("partnerName", partnerName);
        dialog.setArguments(arguments);
        return dialog;
    }

    public void setConfirmListener(OnConfirmListener3 listener) {
        mOnConfirmListener = listener;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
            savedInstanceState) {
        if (getDialog() != null && getDialog().getWindow() != null) {
            getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        }
        return inflater.inflate(R.layout.yinsidialog, container, false);
    }

    @Override
    public void onStart() {
        super.onStart();
        if (getDialog() != null && getDialog().getWindow() != null) {
            getDialog().getWindow().setLayout(ScreenUtil.dip2px(300), ScreenUtil.dip2px(200));
        }
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        TextView textView = view.findViewById(R.id.title);
        String text = "本应用非常重视用户的个人信息和隐私保护。您在使用本应用产品及/或服务时本应用可能会收集和使用您的相关信息。本应用希望通过本<font color='#0ca6f0'>《隐私政策》</font>向您说明，在使用本应用产品及/或服务时，本应用如何收集、使用、分享、保存和管理这些信息。";
        textView.setText(Html.fromHtml(text));

        view.findViewById(R.id.confirm).setOnClickListener(v -> {
            if (mOnConfirmListener != null) {
                mOnConfirmListener.onConfirm();
            }
        });
        view.findViewById(R.id.title).setOnClickListener(v -> {
            if (mOnConfirmListener != null) {
                mOnConfirmListener.onConfirmYinsi();
            }
        });

        view.findViewById(R.id.cancel).setOnClickListener(v -> dismiss());

    }
}
